<?php

namespace App\Common\Exception\Handler;

use App\Common\Exception\ExceptionHandlerInterface;
use App\Common\Util\Response;
use think\exception\ValidateException;

/**
 * Class ValidateExceptionHandler
 */
class ValidateExceptionHandler implements ExceptionHandlerInterface
{

    private \Throwable|ValidateException $throwable;

    public function __construct(\Throwable $throwable)
    {
        $this->throwable = $throwable;
    }

    public function handle(): mixed
    {
        return Response::json()->fail($this->throwable->getError());
    }

    public function isStop(): bool
    {
        return true;
    }
}